package net.lanelife.casino.caipiao.service.award;

import java.util.List;

import net.lanelife.casino.caipiao.entity.BetRecord;
import net.lanelife.casino.caipiao.entity.LotteryNumber;
import net.lanelife.casino.caipiao.entity.User;
import net.lanelife.casino.caipiao.service.api.IBetRecordService;
import net.lanelife.casino.caipiao.service.api.IUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
public class BetGroupAwarder {
	
	@Autowired
	private IUserService userService;
	
	@Autowired
	private IBetRecordService betRecordService;

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public void award(BetGroup.Member member, LotteryNumber lotteryNumber) {
		
		User user = userService.find(member.getUser().getId());
		List<User> parents = userService.findParentsByPath(user.getPath());
		
		
		for (BetRecord br : member.getBetRecords()) {
			
			br.setLotteryNumber(lotteryNumber.getLotteryNumber());
			if (member.getUser().getId()==22 && br.getId()==5) {
				//br.setLotteryNumber("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
			}
			//betRecordService.save(br);
		
			
		}
		
		
		
	}

}
